package com.starbaba.system.index.dao;

import java.util.ArrayList;
import java.util.List;

import com.starbaba.core.hibernate.DAOFactory;
import com.starbaba.core.hibernate.HibernateDAO;
import com.starbaba.core.hibernate.Strategy;
import com.starbaba.system.user.model.UserVO;
import com.starbaba.system.userofgroup.model.UserOfGroupVO;

@SuppressWarnings({"serial","unchecked"})
public class QueryUserOfGroupStrategy implements Strategy {
	private UserVO userVO;

	public QueryUserOfGroupStrategy(UserVO userVO) {
		super();
		this.userVO = userVO;
	}

	@Override
	public Object process() throws Exception {
		HibernateDAO queryDao = DAOFactory.getInstance().createHibernateDAO(UserOfGroupVO.class);
		
		StringBuffer hql = new StringBuffer();	
		hql.append(" SELECT groupid FROM ");
		hql.append(UserOfGroupVO.class.getName()).append(" as ug ");
		hql.append(" where ug.userid = ? "  );
		List<Long> groupIdList = (List<Long>)queryDao.findByHQL(hql.toString(), new Object[]{userVO.getUserid()});
		if(null == groupIdList) return new ArrayList<Long>();
		return groupIdList;
	}

	/**
	 * @return userVO
	 */

	public UserVO getUserVO() {
		return userVO;
	}

	/**
	 * @param userVO
	 *            the userVO to set
	 */
	public void setUserVO(UserVO userVO) {
		this.userVO = userVO;
	}

}
